package ${config.packageName}${module}<#noparse>.</#noparse>${config.controller.packageName};

import com.falcon.mvc.domain.BasePager;
import com.falcon.mvc.domain.BaseResponse;
import com.falcon.mvc.base.IBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

import ${config.packageName}<#noparse>.</#noparse>${config.dto.packageName}<#noparse>.</#noparse>${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''};
import ${config.packageName}<#noparse>.</#noparse>${config.query.packageName}<#noparse>.</#noparse>${config.query.namePrefix!''}${table.className}${config.query.nameSuffix!''};
import ${config.packageName}<#noparse>.</#noparse>${config.request.packageName}<#noparse>.</#noparse>${config.request.namePrefix!''}${table.className}${config.request.nameSuffix!''};
import ${config.packageName}<#noparse>.</#noparse>${config.serviceApi.packageName}<#noparse>.</#noparse>${config.serviceApi.namePrefix!''}${table.className}${config.serviceApi.nameSuffix!''};

@Slf4j
@RestController
@RequestMapping("/${module!''}/${table.className?uncap_first}")
@Tag(name = "${config.controller.namePrefix!''}${table.className}${config.controller.nameSuffix!''}", description = "${table.comment}-接口")
public class ${config.controller.namePrefix!''}${table.className}${config.controller.nameSuffix!''}  implements IBaseController {

    @Autowired
    private ${config.serviceApi.namePrefix!''}${table.className}${config.serviceApi.nameSuffix!''} ${table.className?uncap_first}${config.serviceApi.nameSuffix!''};

    @Operation(summary = "新增")
    @PostMapping("/save")
    public BaseResponse<Long> save(@Valid @RequestBody ${config.request.namePrefix!''}${table.className}${config.request.nameSuffix!''} request) {

        Long id =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/update/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody ${config.request.namePrefix!''}${table.className}${config.request.nameSuffix!''} request) {

        Boolean success =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteById(@PathVariable Long id) {

        Boolean success =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public BaseResponse<Integer> batchDelete(@RequestBody List<Long> ids) {

        Integer num =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.batchDelete(ids);

        return BaseResponse.success(num);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''}> detail(@PathVariable Long id) {

        ${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''} ${config.dto.namePrefix!''}${table.className?uncap_first}Do =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.queryById(id);

        return BaseResponse.success(${table.className?uncap_first}Do);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''}>> list(@RequestBody ${table.className}Query request) {

        List<${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''}> list =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public BaseResponse<BasePager<${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''}>> pager(@RequestBody ${table.className}Query request) {

        BasePager<${config.dto.namePrefix!''}${table.className}${config.dto.nameSuffix!''}> pager =  this.${table.className?uncap_first}${config.serviceApi.nameSuffix!''}.queryPager(request);

        return BaseResponse.success(pager);
    }


}
